import { Navigate } from 'react-router-dom';
import { lazy, Suspense } from 'react';
import routeConfig from '@/config/routeConfig';
import { ReactRouterProps } from './model';
const routes: ReactRouterProps[] = [
    {
        path: '/',
        element: <Navigate to={'/home'} />,
        meta: {},
    },
];
// 获取所有依照规范建的页面
const modules = import.meta.glob<{ default: React.ComponentType<any>}>("@/pages/**/*/index.tsx");
for (const [pathKey, moduleImport] of Object.entries(modules)) {
    if (pathKey.includes('components') || pathKey.includes('layouts')) {
        continue;
    }
    const matchResult = pathKey.match(/\/pages\/(.*)\//);
    if (!matchResult) {
        continue;
    }
    const pageName = matchResult[1];
    let idArr = pageName.split('/'), id = idArr[idArr.length - 1];
    const { name = id, meta = {} } = routeConfig[pageName] || {};
    const LazyComponent = lazy(() => moduleImport());
    routes.push({
        path: '/' + pageName,
        name,
        id,
        element: <Suspense fallback={<div>loading....</div>}><LazyComponent /></Suspense>,
        meta
    });
}
export default routes;
